import request from '@/utils/request'

export function getAnswerDetailsData(content_id) {
  return request({
    url: `/content/${content_id}`,
    method: 'get'
  })
}

export function getAnswer(question_id, sort = 'star_count', per_page = 100) {
  return request({
    url: `/content/answer`,
    method: 'get',
    params: {
      question_id,
      sort,
      per_page
    }
  })
}

export function getRecommend(
  topic_name,
  type = 'question',
  sort = 'weight',
  per_page = 3
) {
  return request({
    url: `/content`,
    method: 'get',
    params: {
      topic_name,
      type,
      sort,
      per_page
    }
  })
}

export function getArticle(
  topic_name,
  type = 'article',
  sort = 'weight',
  per_page = 3
) {
  return request({
    url: `/content`,
    method: 'get',
    params: {
      topic_name,
      type,
      sort,
      per_page
    }
  })
}

export function getContentRecomm(params) {
  return request({
    url: `/content/recomm`,
    method: 'get',
    params
  })
}

export function getProject(params) {
  return request({
    url: `/project`,
    method: 'get',
    params
  })
}

export function getHospitalList(params) {
  return request({
    url: `/hospital/list`,
    method: 'get',
    params
  })
}

export function getHospitalListAd(params, token) {
  return request({
    url: `/advertising`,
    method: 'get',
    headers: { Authorization: token },
    params
  })
}

export function getAnonymousToken(unique_id, _channel) {
  if (_channel) {
    return request({
      url: `/auth/tourist`,
      method: 'post',
      data: {
        unique_id,
        register_channel: _channel
      }
    })
  } else {
    return request({
      url: `/auth/tourist`,
      method: 'post',
      data: {
        unique_id
      }
    })
  }
}

// 埋点
export function exposureReq(url) {
  return request({
    url,
    method: 'get'
  })
}
